package com.openwater.tools.math;

import android.util.FloatMath;

public class Vector2f {

    public float x;
    public float y;

    public Vector2f() {
        setZero();
    };

    public Vector2f(float x, float y) {
        set(x, y);
    };

    public Vector2f(Vector2f v) {
        set(v);
    };

    public Vector2f setZero() {
        return set(0, 0);
    }

    public Vector2f set(Vector2f v) {
        return set(v.x, v.y);
    }

    public Vector2f set(float x, float y) {
        this.x = x;
        this.y = y;
        return this;
    }

    public Vector2f add(Vector2f v) {
        x += v.x;
        y += v.y;
        return this;
    }

    public Vector2f subtraction(Vector2f v) {
        x -= v.x;
        y -= v.y;
        return this;
    }

    public Vector2f multiply(float val) {
        x *= val;
        y *= val;
        return this;
    }

    public Vector2f divide(float val) {
        x /= val;
        y /= val;
        return this;
    }

    public float lenghtSquare() {
        return x * x + y * y;
    }

    public float lenght() {
        return FloatMath.sqrt(lenghtSquare());
    }
}
